import { Component } from '@angular/core';
import { NavController ,ItemSliding} from 'ionic-angular';
import { Task } from './task';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  tasks: Array<Task> =[];
  
  constructor(public navCtrl: NavController) {

  }

  ionViewDidLoad(){
    this.tasks = [
      {title: '早起', status: 'open'},
      {title: '早睡', status: 'open' },
      {title: '吃饱', status: 'open' },
      {title: '泡妹', status: 'open' },
    ];
    }
    
  addTask(){
    let theNewTask: string = prompt("大哥，来：");
    if(theNewTask !== ''){
      this.tasks.push({title: theNewTask, status: 'open'});
    }
  }

  markAsDone(slidingItem: ItemSliding, task: Task){
    task.status = 'done';
    slidingItem.close();

  }
  removeTask(slidingItem: ItemSliding,task: Task){
    task. status = 'removed' ;
    let index = this.tasks.indexOf(task) ;
    if(index > -1){
      this.tasks.splice(index,1);
    }
    slidingItem.close;
  }
    
}
